import jsCookie from 'js-cookie'
import session from '../../util/session'
import { logout } from '../../vuex/action'
import ModalSearchPortfolio from '../modal-search-portfolio/modal-search-portfolio.vue'

export default {
  name: 'Header',
  data() {
    return {
      isShowHeader: true,
      user: '未登陆'
    }
  },
  components: {
    'vue-search-portfolio': ModalSearchPortfolio
  },
  vuex: {
    actions: {
      xLogout: logout
    }
  },
  methods: {
    initUserName() {
      let user = session.get('user_name')
      if (user) {
        this.user = user
      }
    },
    logout() {
      jsCookie.remove(SESSION_COOKIE_NAME)
      session.remove('user_name')
      this.xLogout()
        .then(() => {
          window.location.href = client.htmlPath + '/login.html'
        })
    },
    toogleShowHeader(isShowHeader) {
      this.isShowHeader = isShowHeader
    }
  },
  ready() {
    this.initUserName()
  }
}
